﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityBinder.Interface;

namespace EntityBinder.Binder
{
	public class ContentBinder : IBinder
	{
		public virtual BinderType BinderType
		{
			get
			{
				return Interface.BinderType.VALUE;
			}
		}

		private ITransformer m_transformer;

		public ITransformer Transformer
		{
			get { return m_transformer; }
		}

		public ContentBinder(ITransformer _transformer)
		{
			m_transformer = _transformer;
		}

		public virtual object Read(object _source, string _content, IMemberAccess _memberAccess)
		{
			object transformerData = Transformer.Read(_content);
			if (_memberAccess != null)
			{
				_memberAccess.Set(_source, transformerData);
			}
			return transformerData;
		}

		public virtual string Write(object _source, IMemberAccess _memberAccess)
		{
			return Transformer.Write(_memberAccess.Get(_source));
		}
	}
}
